﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Kcadastro.adm
{
    public partial class agendamento_list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //TODO: BEGIN Seleciona Link Serviços
            if (this.Master is kcadastro)
            {
                ((kcadastro)this.Page.Master).SelecionaPagina(FW.utils.enumPaginas.Agendamentos);
            }
            //TODO:END
            masterPageKcad m = Master as masterPageKcad;
            m.idFerr = 6;
            if (!IsPostBack)
            {
                
                carregar();
            }
        }

        private void carregar()
        {
            int c = 1;
            dd_stts.Items.Insert(0, new ListItem("TODOS", "0"));
            foreach (classes.STTS st in Enum.GetValues(typeof(classes.STTS)))
            { 
                dd_stts.Items.Insert(c, new ListItem(st.ToString(), ((int)st).ToString()));
                c++;
            }
            dd_stts.SelectedIndex = 0;
            carregarGV();
        }
        private void carregarGV()
        {
            classes.oss os = new classes.oss();
            //gv_lista.PageIndex = 0;
            gv_lista.DataSource = os.agendamentos(Convert.ToInt16(dd_stts.SelectedValue));
            gv_lista.DataBind();
            os = null;
        }

        protected void dd_stts_SelectedIndexChanged(object sender, EventArgs e)
        {
            carregarGV();
        }

        protected void gv_lista_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToString() == "visualizar")
            {
                //int ind = Convert.ToInt32(e.CommandArgument);
                //DataKey data = gv_lista.DataKeys[ind];
                //Session.Add("IDeemp", data.Values["PK_IDemp"].ToString());
                //Response.Redirect("empresas_edit.aspx", true); //?id=" + data.Values["PK_IDos"].ToString()
            }
        }

        protected void gv_lista_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            classes.oss os = new classes.oss();
            gv_lista.PageIndex = e.NewPageIndex;
            gv_lista.DataSource = os.agendamentos(Convert.ToInt16(dd_stts.SelectedValue));
            gv_lista.DataBind();
            os = null;
        }
    }
}